#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)
#define FOR(i,a,b) for (int i = a; i <= b; i ++)
#define DOW(i,a,b) for (int i = b; i >= a; -- i)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int date;

int days[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

int check(int date) {
    string s = to_string(date);
    string p = s;
    reverse(s.begin(), s.end());
    if (s != p) return 0;
    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(4, 2));
    int d = stoi(s.substr(6, 2));
    if (m >= 13) return 0;
    if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) {
        if (d <= days[1][m]) {
            if (p[0] == p[2] && p[1] == p[3])
                return 2;
            return 1;
        }
        return 0;
    } else {
        if (d <= days[0][m]) {
            if (p[0] == p[2] && p[1] == p[3])
                return 2;
            return 1;
        }
        return 0;
    }
}

int h1, h2;

inline void solution() {
    cin >> date;
    FOR(i, date + 1, 99999999) {
        int res = check(i);
        if (!h1 && res) h1 = i;
        if (!h2 && res == 2) h2 = i;
        if (h2 && h1) {cout << h1 << endl << h2 << endl; return ;}
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}